#!/bin/sh
# Starts and stops mserver
#

MSERVER_DIR="/opt/mserver/"
MSERVER_BIN="$MSERVER_DIR/src/mserver"
MSERVER_CONFIG="$MSERVER_DIR/config/mserver.config"
PID_FILE="/var/run/mserver.pid"
RUN_USER="squidy"

case "$1" in
start)
	echo -n "Starting mserver..."

	start-stop-daemon -m -b --pidfile $PID_FILE --user $RUN_USER --start --exec $MSERVER_BIN --chuid $RUN_USER -- -c $MSERVER_CONFIG

	echo "OK"
;;

stop)
	echo -n "Stopping mserver..."
	
	start-stop-daemon --stop --pidfile $PID_FILE  --retry 5

	echo "OK"
;;

restart)
  	$0 stop
  	$0 start
;;

status)
             if pidof -o %PPID $MSERVER_BIN > /dev/null; then
                     echo "Running"
                     exit 0
             else
                     echo "Not running"
                     exit 1
             fi
;;

*)
        echo "Usage: $0 {start|stop|restart|status}"
        exit 1
esac
